<template>
    <div id="content">
      <div id="play2" :style="{backgroundImage: 'url(' + cover + ')'}"></div>
      <el-tabs v-model="activeName" @tab-click="handleClick" id="type">
        <el-tab-pane label="全部" name="first">
  
          <ul class="topList-item">
            <li class="topList-img" v-for="(item,index) in list" :key="index" @dblclick="playMusic(item.id)">
              <img :src="item.album.picUrl" alt="" class="image">
              <span class="wen">{{item.name}}</span>
              <span class="author">{{item.album.artists["0"].name}}</span>
              <span class="album">{{item.album.name}}</span>
              <span class="time">{{item.duration}}</span>
            </li>
          </ul>
  
        </el-tab-pane>
        <el-tab-pane label="欧美" name="second">
          <ul class="topList-item">
            <li class="topList-img" v-for="(item,index) in list" :key="index" @dblclick="playMusic(item.id)">
              <img :src="item.album.picUrl" alt="" class="image">
              <span class="wen">{{item.name}}</span>
              <span class="author">{{item.album.artists["0"].name}}</span>
              <span class="album">{{item.album.name}}</span>
              <span class="time">{{item.duration}}</span>
            </li>
          </ul>
        </el-tab-pane>
        <el-tab-pane label="日本" name="third">
          <ul class="topList-item">
            <li class="topList-img" v-for="(item,index) in list" :key="index" @dblclick="playMusic(item.id)">
              <img :src="item.album.picUrl" alt="" class="image">
              <span class="wen">{{item.name}}</span>
              <span class="author">{{item.album.artists["0"].name}}</span>
              <span class="album">{{item.album.name}}</span>
              <span class="time">{{item.duration}}</span>
            </li>
          </ul>
        </el-tab-pane>
        <el-tab-pane label="韩国" name="fourth">
          <ul class="topList-item">
            <li class="topList-img" v-for="(item,index) in list" :key="index" @dblclick="playMusic(item.id)">
              <img :src="item.album.picUrl" alt="" class="image">
              <span class="wen">{{item.name}}</span>
              <span class="author">{{item.album.artists["0"].name}}</span>
              <span class="album">{{item.album.name}}</span>
              <span class="time">{{item.duration}}</span>
            </li>
          </ul>
        </el-tab-pane>
        <el-tab-pane label="华语" name="fifth">
          <ul class="topList-item">
            <li class="topList-img" v-for="(item,index) in list" :key="index" @dblclick="playMusic(item.id)">
              <img :src="item.album.picUrl" alt="" class="image">
              <span class="wen">{{item.name}}</span>
              <span class="author">{{item.album.artists["0"].name}}</span>
              <span class="album">{{item.album.name}}</span>
              <span class="time">{{item.duration}}</span>
            </li>
          </ul>
        </el-tab-pane>
      </el-tabs>
      <div id="header">
        <span>音乐标题</span>
        <span>歌手</span>
        <span>专辑</span>
        <span>时长</span>
      </div>
  
  
    </div>
  </template>
  <script>
    import axios from 'axios'
    export default {
      data() {
        return {
          list: [],
          activeName: 'first',
          tag: "0",
          cover:""
        }
      },
      methods: {
        playMusic(id) {
          axios({
            url: 'http://music.eleuu.com/song/url',
            method: 'get',
            params: {
              id
            }
          }).then(res => {
            console.log(res);
            if (res.data.data[0].url != null) {
              this.$parent.$parent.$children[3].playmusic(id)
            } else {
              // alert('不能播放该歌曲')
              this.$message({
                message: '不能播放该歌曲哟',
                type: 'error'
              });
            }
          })
          axios({
              url: 'http://music.eleuu.com/song/detail',
              method: 'get',
              params: {
                ids: id
              }
            }).then(res => { 
              console.log(this.cover);
              this.cover = res.data.songs[0].al.picUrl;
              // song.cover = data.cover
            })
        },
        handleClick(tab, event) {
          if (tab.label == "全部") {
            this.tag = 0
          }
          if (tab.label == "欧美") {
            this.tag = 96
          }
          if (tab.label == "日本") {
            this.tag = 8
          }
          if (tab.label == "韩国") {
            this.tag = 16
          }
          if (tab.label == "华语") {
            this.tag = 7
          }
         
          axios({
            url: 'http://music.eleuu.com/top/song',
            method: 'get',
            params: {
              type: this.tag
            }
          }).then(res => {
            this.list = res.data.data
            for (let i = 0; i < this.list.length; i++) {
              let min = parseInt(this.list[i].duration / 1000 / 60)
              let sec = parseInt((this.list[i].duration / 1000) % 60)
              if (min < 10) {
                min = '0' + min
              }
              if (sec < 10) {
                sec = '0' + sec
              }
              this.list[i].duration = min + ":" + sec
            }
          })
        
        },
  
      },
      created() {
        axios({
          url: 'http://music.eleuu.com/top/song',
          method: 'get',
          params: {
            type: 0
          }
        }).then(res => {
          this.list = res.data.data
          for (let i = 0; i < this.list.length; i++) {
            let min = parseInt(this.list[i].duration / 1000 / 60)
            let sec = parseInt((this.list[i].duration / 1000) % 60)
            if (min < 10) {
              min = '0' + min
            }
            if (sec < 10) {
              sec = '0' + sec
            }
            this.list[i].duration = min + ":" + sec
          }
        })
      },
  
    }
  
  </script>
  <style scoped>
      #play2 {
      position: fixed;
      left: 81%;
      top: 24%;
      width: 200px;
      height: 200px;
      background-size: 200px 200px;
  
    }
    #type {
      position: fixed;
      left: 120px;
      top: 150px;
      width: 300px;
      height: 100px;
    }
  
    #heading {
      position: fixed;
      left: 110px;
      top: 200px;
      height: 600px;
      width: 1000px;
    }
  
    .el-tabs__item {
      color: white;
    }
  
    #content {
      color: rgb(255, 255, 255, 0.8);
      position: absolute;
      left: 0%;
      top: 50px;
      /* overflow-y: scroll; */
      /* overflow-x: hidden; */
      height: 400px;
      width: 1090px
    }
  
    ul {
      list-style: none;
      position: absolute;
      top: 30px;
      left: 0px;
      width: 1050px;
      height: 430px;
      overflow-y: scroll;
    }
  
    .topList-head {
      color: white;
      font-size: 20px;
      position: absolute;
      left: 8%;
      top: 0%;
    }
  
    .topList-head1 {
      color: white;
      font-size: 20px;
      position: absolute;
      left: 8%;
      top: 270%;
    }
  
    .topList-content {
      position: absolute;
      top: 48%;
      left: -2%;
      height: 50%;
      overflow: hidden;
      width: 100%;
      overflow-y: scroll;
      /* border: 1px solid white; */
    }
  
    ::-webkit-scrollbar {
      width: 8px;
      height: 8px;
    }
  
    /*定义滚动条轨道 内阴影+圆角*/
    ::-webkit-scrollbar-track {
      border-radius: 4px;
      background-color: rgba(0, 0, 0, 0.3);
    }
  
    /*定义滑块 内阴影+圆角*/
    ::-webkit-scrollbar-thumb {
      border-radius: 5px;
      background-color: rgb(255, 255, 255, 0.7);
    }
  
    .image {
      width: 60px;
      height: 60px;
      object-fit: cover;
      border-radius: 5px;
      position: absolute;
      left: 10px;
      top: 10px;
    }
  
    .topList-img {
      position: relative;
      width: 1000px;
      height: 85px;
      margin: 0px 5px 0px 10px;
      /* float: left; */
    }
  
    .topList-img1 {
      width: 150px;
      height: 125px;
      margin: 40px 20px;
      float: left;
      position: relative;
      top: 70px;
    }
  
    img {
      width: 100%;
      height: 100%;
    }
  
    .wen {
      position: absolute;
      left: 130px;
      top: 30px;
      font-size: 14px;
    }
  
    .author {
      position: absolute;
      left: 380px;
      top: 30px;
      font-size: 14px;
    }
  
    .album {
      position: absolute;
      width: 120px;
      left: 660px;
      top: 30px;
      font-size: 14px;
      text-align: left;
    }
  
    .time {
      position: absolute;
      left: 883px;
      top: 30px;
      font-size: 14px;
    }
  
    #header {
      position: fixed;
      left: 240px;
      top: 210px;
    }
  
    #header span {
      position: absolute;
      left: 0px;
      width: 100px;
    }
  
    #header :nth-child(2) {
      left: 235px;
    }
  
    #header :nth-child(3) {
      left: 515px;
    }
  
    #header :nth-child(4) {
      left: 740px;
    }
  
  </style>
  